package cn.edu.hyit.hjq.volunteems.backend.service.impl;

import cn.edu.hyit.hjq.volunteems.backend.dto.request.RegistrationRequest;
import cn.edu.hyit.hjq.volunteems.backend.mapper.RegistrationMapper;
import cn.edu.hyit.hjq.volunteems.backend.service.RegistrationService;
import org.springframework.stereotype.Service;

@Service
public class RegistrationServiceImpl implements RegistrationService {

    private final RegistrationMapper registrationMapper;

    public RegistrationServiceImpl(RegistrationMapper registrationMapper) {
        this.registrationMapper = registrationMapper;
    }

    @Override
    public void register(RegistrationRequest request) {
        int count = registrationMapper.countByVolunteer(request.getVolunteerId());
        if (count >= 3) {
            throw new RuntimeException("每位志愿者最多只能报名3个活动");
        }

        registrationMapper.insert(request.getActivityId(), request.getVolunteerId());
    }
}
